package org.jeecg.jxc.supplierManagement.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.api.vo.Result;
import org.jeecg.jxc.supplierManagement.entity.TSupplier;
import org.jeecg.jxc.supplierManagement.service.TSupplierService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * @description:
 * @company:yaorange
 * @author:Mr.Gao
 * @version:1.0
 * @create:2022-06-21 16:49:43
 */
@RestController
@RequestMapping("/supplier")
public class TSupplierController {

    @Resource
    private TSupplierService tSupplierService;

    @GetMapping("/getAllList")
    public IPage<TSupplier> getPage(@RequestParam(value = "page" ,defaultValue = "1") Integer page,@RequestParam(value = "rows", defaultValue = "5") Integer rows) {
        Page<TSupplier> tSupplierPage = new Page<>(page, rows);
        return tSupplierService.pageList(tSupplierPage);
    }
    @GetMapping("/list")
    public IPage<TSupplier> getPage(@RequestParam("page") Integer page,@RequestParam("rows") Integer rows,@RequestParam(value = "supplierName") String supplierName) {
        Page<TSupplier> tSupplierPage = new Page<>(page, rows);
        return tSupplierService.page(tSupplierPage,supplierName);
    }

    @PostMapping("/save")
    public Result<?> add(@RequestBody TSupplier tSupplier){
        int rows = tSupplierService.addUser(tSupplier);
        if(rows > 0){
            return Result.OK("新增成功",null);
        }
        return Result.error("新增失败");
    }

    @PutMapping("/update")
    public Result<?> update(@RequestBody TSupplier tSupplier){
        int rows = tSupplierService.updateUser(tSupplier);
        if(rows > 0){
            return Result.OK("更新成功",null);
        }
        return Result.error("更新失败");
    }

    @GetMapping("/delete")
    public Result<?> delet(Integer id) {
        int rows = tSupplierService.delet(id);
        if (rows > 0) {
            return Result.ok("删除成功");
        }
        return Result.error("删除失败");
    }
    @PostMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> ids) {
        int rows = tSupplierService.delets(ids);
        if (rows > 0) {
            return Result.ok("删除成功");
        }
        return Result.error("删除失败");
    }
}
